package com.cheung.leetcode.lcp;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.lcp
 * @Author :  cheungming
 * @CreateTime : 2024-06-21 07:34:43
 * @Description : 气温变化趋势
 * @Version : 1.0
 */
public class Code61Test {

    public int temperatureTrend(int[] temperatureA, int[] temperatureB) {

        int maxTrend = 0;
        int currentTrend = 0;
        for (int i = 1; i < temperatureA.length; i++) {
            if (Integer.compare(temperatureA[i - 1], temperatureA[i])
                    == Integer.compare(temperatureB[i - 1], temperatureB[i])) {
                currentTrend++;
                maxTrend = Math.max(maxTrend, currentTrend);
            } else {
                currentTrend = 0;
            }
        }

        return maxTrend;
    }


    @Test
    public void test1() {
        int[] temperatureA = {21, 18, 18, 18, 31};
        // -1,0,0,1
        int[] temperatureB = {34, 32, 16, 16, 17};
        // -1,-1,0,1
        assert temperatureTrend(temperatureA, temperatureB) == 2;
    }

    @Test
    public void test2() {
        int[] temperatureA = {5, 10, 16, -6, 15, 11, 3};
        // 1,1,-1,1,-1,-1
        int[] temperatureB = {16, 22, 23, 23, 25, 3, -16};
        // 1,1,0,1,-1,-1
        assert temperatureTrend(temperatureA, temperatureB) == 3;
    }
}
